﻿/*****************************************************************//**
 * @file    FITKGraphObjectBeamOrientationPreview.h
 * @brief   Graph object for previewing beam orientation.
 *
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-07-09
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTBEAMORIENTATIONPREVIEW_H__
#define __FITKGRAPHOBJECTBEAMORIENTATIONPREVIEW_H__

#include "FITKGraphObjectFixedSizeBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkPoints;
class vtkUnstructuredGrid;
class vtkTextProperty;
class vtkStringArray;
class vtkDoubleArray;

class FITKGraphActor;
class FITKGraphActor2D;
class FITKCoordinateAlgorithmEX;

namespace Interface
{
    class FITKAbaBeamOrientation;
    class FITKModelSet;
}

namespace Exchange
{
    /**
     * @brief   Graph object for previewing beam orientation.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-07-09
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectBeamOrientationPreview : public FITKGraphObjectFixedSizeBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectBeamOrientationPreview, FITKGraphObjectFixedSizeBase);
        FITKCLASS(Exchange, FITKGraphObjectBeamOrientationPreview);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   beamOrient: The beam orientation data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphObjectBeamOrientationPreview(AbaqusData::FITKDataCase* caseData, Interface::FITKAbaBeamOrientation* beamOrient);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        ~FITKGraphObjectBeamOrientationPreview();

        /**
         * @brief   Show or hide graph object.[override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void setVisible(bool visibility) override; 

        /**
         * @brief   Update all graph actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   If the graph object has relation with the given data object id.[override]
         * @param   dataObjId: The data object id
         * @return  Has relation
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        bool isRelatedTo(int dataObjId) override;

#ifdef QT_DEBUG
        /**
         * @brief   Simplified the graph object if necessary.[override]
         * @param   enabled: Enabled simplified flag
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void simplified(bool enabled) override;
#endif // QT_DEBUG

    private:
        /**
         * @brief   Initialize.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void init();

        /**
         * @brief   Initialize the actor and data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void initActor();

        /**
         * @brief   Generate the poly data for the orientation axes.
         * @param   beamOrient: The beam orientation data object
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        bool generatePolyData(Interface::FITKAbaBeamOrientation* beamOrient);

        /**
         * @brief   Generate the graph actor with the orientation data.
         * @param   beamOrient: The beam orientation data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void generateGraph();

        /**
         * @brief   Clear the data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void clearData();

        /**
         * @brief   Get the point coordinates with the given origin and direction.
         * @param   origin: The origin
         * @param   direc: The direction
         * @param   pt: The point coordinates
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void getPointByOriginAndDirection(double* origin, double* direc, double* pt);

        /**
         * @brief   Check if the component is valid.
         * @param   compId: The component id( Set or surface )
         * @return  Is valid
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        bool getComponentValid(int compId);

        /**
         * @brief   Get the element set or comp-set members.
         * @param   set: The set data object
         * @param   elementIds: The ids of the elements[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void getPartEleSetMembers(Interface::FITKModelSet* set, QList<int> & elementIds);

        /**
         * @brief   Get the element set members.
         * @param   set: The set data object
         * @param   elementIds: The ids of the elements[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        void getPartEleSetMembersPrivate(Interface::FITKModelSet* set, QList<int> & elementIds);

    private:
        /**
         * @brief   The array name of the direction array for t-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-10
         */
        const char* c_directionArrNameT = "_direction_t_";

        /**
         * @brief   The array name of the direction array for 1-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-10
         */
        const char* c_directionArrName1 = "_direction_1_";

        /**
         * @brief   The array name of the direction array for 2-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-10
         */
        const char* c_directionArrName2 = "_direction_2_";

        /**
         * @brief   The scale filter for t-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKCoordinateAlgorithmEX* m_coordFilterT{ nullptr };

        /**
         * @brief   The scale filter for 1-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKCoordinateAlgorithmEX* m_coordFilter1{ nullptr };

        /**
         * @brief   The scale filter for 2-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKCoordinateAlgorithmEX* m_coordFilter2{ nullptr };

        /**
         * @brief   The axes actor for t-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphActor* m_fActorT{ nullptr };

        /**
         * @brief   The axes actor for 1-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphActor* m_fActor1{ nullptr };

        /**
         * @brief   The axes actor for 2-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphActor* m_fActor2{ nullptr };

        /**
         * @brief   The t-axes label actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphActor2D* m_fActorLabel2DT{ nullptr };

        /**
         * @brief   The 1-axes label actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphActor2D* m_fActorLabel2D1{ nullptr };

        /**
         * @brief   The 2-axes label actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        FITKGraphActor2D* m_fActorLabel2D2{ nullptr };

        /**
         * @brief   The points data for axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        vtkPoints* m_points{ nullptr };

        /**
         * @brief   The axes line grid data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        vtkUnstructuredGrid* m_gridAxes{ nullptr };

        /**
         * @brief   The direction array of the t-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-10
         */
        vtkDoubleArray* m_arrayDirT{ nullptr };

        /**
         * @brief   The direction array of the 1-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-10
         */
        vtkDoubleArray* m_arrayDir1{ nullptr };

        /**
         * @brief   The direction array of the 2-axes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-10
         */
        vtkDoubleArray* m_arrayDir2{ nullptr };

        /**
         * @brief   The text property for the t-axes labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        vtkTextProperty* m_textPropertyT{ nullptr };

        /**
         * @brief   The text property for the 1-axes labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        vtkTextProperty* m_textProperty1{ nullptr };

        /**
         * @brief   The text property for the 2-axes labels.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        vtkTextProperty* m_textProperty2{ nullptr };

        /**
         * @brief   The set id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        int m_setId = -1;

        /**
         * @brief   Wether the n1 is valid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-09
         */
        bool m_hasN1 = false;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTBEAMORIENTATIONPREVIEW_H__
